#include <string>
#include <iostream>

#include "featureCreation.h"

using namespace std;
using namespace pip;

//  simpledigitclassifier -trainImages filename -trainLabels filename -testImages filename  -result filename
int main(int argc, char *argv[])
{
  const string program = argv[0];
  vector<string> args(argv, argv + argc);
  if (argc < 6) {// are there at least enough parameter to run the program?
    error(program, "Usage: PROGRAM -trainImages FILENAME -trainLabels FILENAME -testImages FILENAME  -result FILENAME");
  }

  string trIm(" "), trLa(" "), teIm(" "), result("results.pip"); // init strings

  getScalarArg(args, "-trainImages", trIm);       // accept parameter as required
  getScalarArg(args, "-trainLabels", trLa); 
  getScalarArg(args, "-testImages" , teIm); 
  getScalarArg(args, "-result"     , result); 

  vector<string> trainfiles, testfiles;

  DataSet trainingds,testds;

cout << "\n=>reading samples..." << endl;
  getFeatureLabels(trIm, trainingds, trLa);
cout << "\n=>training phase...\t(may take a while)" << endl;
  ImageMean nm;
  nm.train(trainingds);
  nm.trainknn(trainingds);


 
cout << "\n=>preparing test samples..." << endl;
  getFeatureLabels(teIm,  testds);
  
cout << "\n=>constructing results..." << endl;
  unsigned int length = testds.samples().size(); // how many samples were tested?
  Image<unsigned char> out(Dimension(length,0)); // prepare a image
  for(unsigned int len = 0 ; len < length ; ++len){
	out(len,0) = nm.testknn(testds.sample(len));    // to save the results in
  }
  
  if(!exportFile(out, result)){
	error(program, "...fails to save result \a..."); //and store this image to disc
  }
  
cout << "\n=>DONE" << endl;

  system("pause");
  return 0;
}